﻿Imports HMSLibrary
Imports System.Collections.ObjectModel

Public Class PatientDataLayer
    Inherits PatientDataProvider

    Dim SQLQuery As String = String.Empty

    Public Overrides Function GetPatientByID(ByVal ID As Integer) As HMSLibrary.PatientRegistration
        Dim patientObject As PatientRegistration = Nothing
        Try
            Dim dr As IDataReader
            SQLQuery = "EXEC Proc_GetPatientbyID " & ID
            dr = DataCommon.db.ExecuteReader(CommandType.Text, SQLQuery)
            If dr.Read = True Then
                patientObject = New PatientRegistration
                patientObject.Address = DataCommon.DBNullCheck(dr.Item("Address"))
                patientObject.Age = DataCommon.DBNullCheck(dr.Item("Age"))
                patientObject.AssignedDr = DataCommon.DBNullCheck(dr.Item("AssignedDr"))
                patientObject.bloodGroup = DataCommon.DBNullCheck(dr.Item("BloodGroup"))
                patientObject.childBoys = DataCommon.DBNullCheck(dr.Item("ChildBoys"))
                patientObject.childGirl = DataCommon.DBNullCheck(dr.Item("ChildGirl"))
                patientObject.ContactPerson = DataCommon.DBNullCheck(dr.Item("Contact Person"))
                patientObject.diet = DataCommon.DBNullCheck(dr.Item("Diet"))
                patientObject.DOB = DataCommon.DBNullCheck(dr.Item("DOB"))
                patientObject.Email = DataCommon.DBNullCheck(dr.Item("Email"))
                patientObject.FirstName = dr.Item("FirstName")
                patientObject.Gender = DataCommon.DBNullCheck(dr.Item("Gender"))
                patientObject.image = DataCommon.DBNullCheck(dr.Item("Image"))
                patientObject.language = DataCommon.DBNullCheck(dr.Item("Language"))
                patientObject.LastName = DataCommon.DBNullCheck(dr.Item("LastName"))
                patientObject.MaritalStatus = DataCommon.DBNullCheck(dr.Item("MaritalStatus"))
                patientObject.MobileNo = DataCommon.DBNullCheck(dr.Item("Mobile No"))
                patientObject.Occupation = DataCommon.DBNullCheck(dr.Item("Occupation"))
                patientObject.PatientId = ID
                patientObject.PatientType = DataCommon.DBNullCheck(dr.Item("PatientType"))
                patientObject.RefByDoc = DataCommon.DBNullCheck(dr.Item("RefByDoc"))
                patientObject.RegistrationDate = dr.Item("RegistrationDate")
                patientObject.religion = DataCommon.DBNullCheck(dr.Item("Religion"))
                patientObject.Remarks = DataCommon.DBNullCheck(dr.Item("Remarks"))
                patientObject.siblingBrother = DataCommon.DBNullCheck(dr.Item("SiblingBrother"))
                patientObject.siblingSister = DataCommon.DBNullCheck(dr.Item("SiblingSister"))
                patientObject.SurName = DataCommon.DBNullCheck(dr.Item("SurName"))
                patientObject.TelephoneNo = DataCommon.DBNullCheck(dr.Item("Telephone No"))
            End If
            If dr.IsClosed = False Then dr.Close()
        Catch ex As Exception
            Throw ex
        End Try
        Return patientObject
    End Function

    Public Overrides Function GetPatientList() As List(Of HMSLibrary.PatientRegistration)
        Try
            Dim dr As IDataReader = Nothing
            SQLQuery = "Select * From PatientRegistration order by 1"
            dr = DataCommon.db.ExecuteReader(CommandType.Text, SQLQuery)
            Dim clientList As New List(Of PatientRegistration)
            Dim patientObject As PatientRegistration
            While dr.Read
                patientObject = New PatientRegistration
                patientObject.PatientId = dr.Item("PatientId")
                patientObject.FirstName = dr.Item("FirstName")
                patientObject.LastName = DataCommon.DBNullCheck(dr.Item("LastName"))
                patientObject.SurName = DataCommon.DBNullCheck(dr.Item("SurName"))
                patientObject.Gender = dr.Item("Gender")
                patientObject.Address = DataCommon.DBNullCheck(dr.Item("Address"))
                patientObject.TelephoneNo = DataCommon.DBNullCheck(dr.Item("Telephone No"))
                patientObject.MobileNo = DataCommon.DBNullCheck(dr.Item("Mobile No"))
                patientObject.ContactPerson = DataCommon.DBNullCheck(dr.Item("Contact Person"))
                patientObject.Email = DataCommon.DBNullCheck(dr.Item("Email"))
                patientObject.Remarks = DataCommon.DBNullCheck(dr.Item("Remarks"))
                patientObject.RegistrationDate = dr.Item("RegistrationDate")
                patientObject.RefByDoc = DataCommon.DBNullCheck(dr.Item("RefByDoc"))
                patientObject.DOB = IIf(IsDBNull(dr.Item("DOB")), Nothing, dr.Item("DOB"))
                patientObject.Age = dr.Item("Age")
                patientObject.Occupation = DataCommon.DBNullCheck(dr.Item("Occupation"))
                clientList.Add(patientObject)
            End While
            If dr.IsClosed = False Then dr.Close()
            Return clientList
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Overrides Function GetIPDPatientList() As List(Of AdmissionDisplay)
        Try
            Dim dr As IDataReader = Nothing
            SQLQuery = "Proc_GetAdmittedPatientList"
            dr = DataCommon.db.ExecuteReader(CommandType.StoredProcedure, SQLQuery)
            Dim clientList As New List(Of AdmissionDisplay)
            Dim patientObject As AdmissionDisplay
            While dr.Read
                patientObject = New AdmissionDisplay
                patientObject.AdminssionId = dr.Item("PatientAdmissionID")
                patientObject.PatientId = dr.Item("PatientId")
                patientObject.FirstName = dr.Item("FirstName")
                patientObject.LastName = DataCommon.DBNullCheck(dr.Item("LastName"))
                patientObject.SurName = DataCommon.DBNullCheck(dr.Item("SurName"))
                patientObject.Gender = dr.Item("Gender")
                patientObject.Address = DataCommon.DBNullCheck(dr.Item("Address"))
                patientObject.TelephoneNo = DataCommon.DBNullCheck(dr.Item("Telephone No"))
                patientObject.MobileNo = DataCommon.DBNullCheck(dr.Item("Mobile No"))
                patientObject.ContactPerson = DataCommon.DBNullCheck(dr.Item("Contact Person"))
                patientObject.Age = dr.Item("Age")
                patientObject.AdminssionDate = dr.Item("AdminssionDate")
                patientObject.Complaints = dr.Item("Diseases")
                patientObject.Room = dr.Item("RoomNo")
                patientObject.RoomID = dr.Item("RoomID")
                clientList.Add(patientObject)
            End While
            If dr.IsClosed = False Then dr.Close()
            Return clientList
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Overrides Function GetPatientNameIDList() As List(Of HMSLibrary.Lookups)
        Try
            Dim dr As IDataReader = Nothing
            SQLQuery = "Select FirstName,LastName,SurName,PatientId From PatientRegistration order by 1"
            dr = DataCommon.db.ExecuteReader(CommandType.Text, SQLQuery)
            Dim PatientList As New List(Of Lookups)
            Dim PatientObject As Lookups
            While dr.Read
                PatientObject = New Lookups
                Dim patientName As String
                patientName = dr.Item("FirstName")
                If IsDBNull(dr.Item("LastName")) = False Then
                    patientName = patientName & " " & dr.Item("LastName")
                End If
                If IsDBNull(dr.Item("SurName")) = False Then
                    patientName = patientName & " " & dr.Item("SurName")
                End If
                PatientObject.Name = patientName
                PatientObject.ID = dr.Item("PatientId")
                PatientList.Add(PatientObject)
            End While
            If dr.IsClosed = False Then dr.Close()
            Return PatientList
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Overrides Function SavePatient(ByVal PatientObject As HMSLibrary.PatientRegistration, ByVal Mode As FormAction) As Integer
        Dim objPRM(27) As Object
        objPRM(0) = PatientObject.FirstName
        objPRM(1) = PatientObject.LastName
        objPRM(2) = PatientObject.SurName
        objPRM(3) = PatientObject.Gender
        objPRM(4) = PatientObject.Address
        objPRM(5) = PatientObject.TelephoneNo
        objPRM(6) = PatientObject.MobileNo
        objPRM(7) = PatientObject.ContactPerson
        objPRM(8) = PatientObject.Email
        objPRM(9) = PatientObject.Remarks
        objPRM(10) = PatientObject.PatientType
        objPRM(11) = PatientObject.RegistrationDate
        objPRM(12) = PatientObject.RefByDoc
        objPRM(13) = PatientObject.DOB
        objPRM(14) = PatientObject.Age
        objPRM(15) = PatientObject.Occupation
        objPRM(16) = PatientObject.AssignedDr
        objPRM(17) = PatientObject.MaritalStatus
        objPRM(18) = PatientObject.CreatedBy
        objPRM(19) = PatientObject.language
        objPRM(20) = PatientObject.religion
        objPRM(21) = PatientObject.bloodGroup
        objPRM(22) = PatientObject.diet
        objPRM(23) = PatientObject.siblingBrother
        objPRM(24) = PatientObject.siblingSister
        objPRM(25) = PatientObject.childBoys
        objPRM(26) = PatientObject.childGirl
        objPRM(27) = PatientObject.image
        If Mode = FormAction.ADD Then
            Dim obj As Object
            obj = DataCommon.db.ExecuteScalar("Proc_Insert_PatientRegistration", objPRM)
            If obj Is Nothing Then Return 0
            PatientObject.PatientId = obj
            MsgBox(CommonMessages.AddMessage, MsgBoxStyle.Information, CommonMessages.MessageTitle)
        ElseIf Mode = FormAction.EDIT Then
            ReDim Preserve objPRM(15)
            'objPRM(15) = ClientObject.ID
            'If DataCommon.db.ExecuteNonQuery( "update_tbl_ClientMaster", objPRM) = False Then Exit Function
            MsgBox(CommonMessages.EditMessage, MsgBoxStyle.Information, CommonMessages.MessageTitle)
        End If
        AddPatientGuardianInfo(PatientObject.PatientId, PatientObject.PatientGuardians, Mode)
        Return PatientObject.PatientId
    End Function

    Private Sub AddPatientGuardianInfo(ByVal PatientID As Integer, ByVal guards As ObservableCollection(Of PatientGuardian), ByVal Mode As FormAction)
        Dim objPRM(0) As Object
        objPRM(0) = PatientID
        If Mode = FormAction.EDIT Then
            DataCommon.db.ExecuteNonQuery("Proc_Delete_PatientGuardians", objPRM)
        End If
        ReDim Preserve objPRM(7)
        For Each guard In guards
            objPRM(1) = guard.GuardianName
            objPRM(2) = guard.RelationshipID
            objPRM(3) = guard.ContactNo
            objPRM(4) = guard.healthStatus
            objPRM(5) = guard.age
            objPRM(6) = guard.Complaints
            objPRM(7) = guard.notes
            DataCommon.db.ExecuteNonQuery("Proc_Insert_PatientGuardians", objPRM)
        Next
    End Sub

    Public Overrides Function SavePatientAdmission(ByVal patientID As Integer, ByVal patientObject As HMSLibrary.PatientAddmissionInfo) As Integer
        Dim objPRM(6) As Object
        objPRM(0) = patientID
        objPRM(1) = patientObject.AdminssionDate
        objPRM(2) = patientObject.WardID
        objPRM(3) = patientObject.DepartmentID
        objPRM(4) = patientObject.RoomID
        objPRM(5) = patientObject.Complaints
        objPRM(6) = patientObject.Remarks
        DataCommon.db.ExecuteNonQuery("Proc_Insert_PatientAddmissionInfo", objPRM)
        Return True
    End Function

    Public Overrides Function SavePaymentDetails(ByVal PatientID As Integer, ByVal ReceivedID As Integer, ByVal FormMode As HMSLibrary.FormAction, ByVal BillPaymentDetails As HMSLibrary.BillPayDetails) As Integer
        Dim dl As New BillingDataLayer()
        Dim payID As Integer = dl.SavePaymentDetails(PatientID, Nothing, FormMode, BillPaymentDetails)
        Dim objprm(2) As Object
        objprm(0) = PatientID
        objprm(1) = payID
        objprm(2) = ReceivedID
        If FormMode = FormAction.ADD Then
            DataCommon.db.ExecuteNonQuery("Proc_InsertPatientPayDetails", objprm)
        End If
        Return payID
    End Function

    Public Overrides Function SavePatientVisits(ByVal sender As HMSLibrary.PatientVisit, ByVal Mode As HMSLibrary.FormAction) As Integer
        Try
            Dim objPRM(8) As Object
            objPRM(0) = sender.patientID
            objPRM(1) = sender.visitID
            objPRM(2) = sender.visitDataTime
            objPRM(3) = sender.consultingDoc
            objPRM(4) = sender.consultationRoom
            objPRM(5) = sender.visitStatus
            objPRM(6) = sender.compalinedComplaints
            objPRM(7) = sender.followUpID
            objPRM(8) = sender.visitNote
            If Mode = FormAction.ADD Then
                DataCommon.db.ExecuteNonQuery("Proc_Insert_PatientVisits", objPRM)
                MsgBox(CommonMessages.AddMessage, MsgBoxStyle.Information, CommonMessages.MessageTitle)
            ElseIf Mode = FormAction.EDIT Then
                ReDim Preserve objPRM(15)
                'objPRM(15) = ClientObject.ID
                'If DataCommon.db.ExecuteNonQuery( "update_tbl_ClientMaster", objPRM) = False Then Exit Function
                MsgBox(CommonMessages.EditMessage, MsgBoxStyle.Information, CommonMessages.MessageTitle)
            End If
            SavePatientProblems(sender.patientID, sender.visitID, sender.ProblemList, Mode)
            SavePatientPrescription(sender.patientID, sender.visitID, sender.TreatmentList, Mode)
            SavePatientExamFinding(sender.patientID, sender.visitID, sender.findingList, Mode)
            SavePatientDiagnosis(sender.patientID, sender.visitID, sender.DiagnosisList, Mode)
        Catch ex As Exception
            Return False
        End Try
        Return True
    End Function

    Public Function SavePatientProblems(ByVal patientId As Integer, ByVal VisitID As Integer, ByVal sender As ObservableCollection(Of PatientProblem), ByVal Mode As HMSLibrary.FormAction) As Integer
        Dim i As Integer = 0
        For Each prob In sender
            Dim objPRM(12) As Object
            i = i + 1
            objPRM(0) = patientId
            objPRM(1) = i
            objPRM(2) = VisitID
            objPRM(3) = prob.reportedDateTime
            objPRM(4) = prob.reportedDr
            objPRM(5) = prob.problem
            objPRM(6) = prob.period
            objPRM(7) = prob.problemPeriod
            objPRM(8) = prob.problemTiming
            objPRM(9) = prob.problemDuration
            objPRM(10) = prob.problemLocation
            objPRM(11) = prob.severity
            objPRM(12) = prob.comments
            If Mode = FormAction.ADD Then
                DataCommon.db.ExecuteNonQuery("Proc_Insert_PatientProblems", objPRM)
            ElseIf Mode = FormAction.EDIT Then
                ReDim Preserve objPRM(15)
                'objPRM(15) = ClientObject.ID
                'If DataCommon.db.ExecuteNonQuery( "update_tbl_ClientMaster", objPRM) = False Then Exit Function
            End If
        Next
    End Function

    Public Function SavePatientPrescription(ByVal patientId As Integer, ByVal VisitID As Integer, ByVal sender As ObservableCollection(Of PatientPrescription), ByVal Mode As HMSLibrary.FormAction) As Integer
        Dim i As Integer = 0
        For Each pres In sender
            Dim objPRM(7) As Object
            i = i + 1
            objPRM(0) = patientId
            objPRM(1) = i
            objPRM(2) = VisitID
            objPRM(3) = pres.medicineItemID
            objPRM(4) = pres.dosage
            objPRM(5) = pres.frequency
            objPRM(6) = pres.duaration
            objPRM(7) = pres.periods
            If Mode = FormAction.ADD Then
                DataCommon.db.ExecuteNonQuery("Proc_Insert_PatientPrescription", objPRM)
            ElseIf Mode = FormAction.EDIT Then
                ReDim Preserve objPRM(15)
                'objPRM(15) = ClientObject.ID
                'If DataCommon.db.ExecuteNonQuery( "update_tbl_ClientMaster", objPRM) = False Then Exit Function
            End If
        Next
    End Function

    Public Function SavePatientExamFinding(ByVal patientId As Integer, ByVal VisitID As Integer, ByVal sender As ObservableCollection(Of PatientExamFinding), ByVal Mode As HMSLibrary.FormAction) As Integer
        Dim i As Integer = 0
        For Each find In sender
            Dim objPRM(4) As Object
            i = i + 1
            objPRM(0) = patientId
            objPRM(1) = i
            objPRM(2) = VisitID
            objPRM(3) = find.findCategory
            objPRM(4) = find.findings
            If Mode = FormAction.ADD Then
                DataCommon.db.ExecuteNonQuery("Proc_Insert_PatientExamFinding", objPRM)
            ElseIf Mode = FormAction.EDIT Then
                ReDim Preserve objPRM(15)
                'objPRM(15) = ClientObject.ID
                'If DataCommon.db.ExecuteNonQuery( "update_tbl_ClientMaster", objPRM) = False Then Exit Function
            End If
        Next
    End Function

    Public Function SavePatientDiagnosis(ByVal patientId As Integer, ByVal VisitID As Integer, ByVal sender As ObservableCollection(Of PatientDiagnosis), ByVal Mode As HMSLibrary.FormAction) As Integer
        Dim i As Integer = 0
        For Each dia In sender
            i = i + 1
            Dim objPRM(5) As Object
            objPRM(0) = patientId
            objPRM(1) = i
            objPRM(2) = VisitID
            objPRM(3) = dia.ID
            objPRM(4) = dia.diagnosisDateTime
            objPRM(5) = dia.status
            If Mode = FormAction.ADD Then
                DataCommon.db.ExecuteNonQuery("Proc_Insert_PatienDiagnosis", objPRM)
            ElseIf Mode = FormAction.EDIT Then
                ReDim Preserve objPRM(15)
                'objPRM(15) = ClientObject.ID
                'If DataCommon.db.ExecuteNonQuery( "update_tbl_ClientMaster", objPRM) = False Then Exit Function
            End If
        Next
    End Function

    Public Overrides Function GetPatientLastVisitInfo(ByVal ID As Integer) As HMSLibrary.PatientVisitInfo
        Dim lup As New PatientVisitInfo
        Try
            Dim dr As IDataReader
            SQLQuery = "Exec Proc_GetPatienLastVisitInfo " & ID
            dr = DataCommon.db.ExecuteReader(CommandType.Text, SQLQuery)
            If dr.Read Then
                lup.Age = DataCommon.DBNullCheck(dr.Item("Age"))
                lup.Complain = DataCommon.DBNullCheck(dr.Item("Problem"))
                lup.Doctor = DataCommon.DBNullCheck(dr.Item("Doc"))
                lup.LastVisit = DataCommon.DBNullCheck(dr.Item("VisitDataTime"))
                lup.VisitID = DataCommon.DBNullCheck(dr.Item("VisitID"))
            End If
            dr.Close()
        Catch ex As Exception
            Throw ex
        End Try
        Return lup
    End Function

    Public Overrides Function GetPatientVisitInfo(ByVal ID As Integer) As List(Of HMSLibrary.PatientVisitInfo)
        Dim lst As New List(Of PatientVisitInfo)
        Try
            Dim dr As IDataReader
            SQLQuery = "Exec Proc_GetPatienVisitInfo " & ID
            dr = DataCommon.db.ExecuteReader(CommandType.Text, SQLQuery)
            While dr.Read
                Dim obj As New PatientVisitInfo
                obj.Complain = DataCommon.DBNullCheck(dr.Item("Problem"))
                obj.Doctor = DataCommon.DBNullCheck(dr.Item("Doc"))
                obj.LastVisit = DataCommon.DBNullCheck(dr.Item("VisitDataTime"))
                obj.VisitID = DataCommon.DBNullCheck(dr.Item("VisitID"))
                obj.VisitNote = DataCommon.DBNullCheck(dr.Item("VisitNote"))
                obj.VisitStatus = DataCommon.DBNullCheck(dr.Item("VisitStatus"))
                lst.Add(obj)
            End While
            dr.Close()
        Catch ex As Exception
            Throw ex
        End Try
        Return lst
    End Function

    Public Overrides Function GetPatientVisitCompleteInfo(ByVal PatientID As Integer, ByVal VisitID As Integer) As HMSLibrary.PatientVisit
        Dim patVisit As New PatientVisit
        Try
            patVisit.ProblemList = New ObservableCollection(Of PatientProblem)()
            patVisit.findingList = New ObservableCollection(Of PatientExamFinding)()
            patVisit.DiagnosisList = New ObservableCollection(Of PatientDiagnosis)
            patVisit.TreatmentList = New ObservableCollection(Of PatientPrescription)
            Dim dr As IDataReader
            Dim objPrm(1) As Object
            objPrm(0) = PatientID
            objPrm(1) = VisitID
            SQLQuery = "Proc_GetPatientVisit"
            dr = DataCommon.db.ExecuteReader(SQLQuery, objPrm)
            If dr.Read Then
                patVisit.visitDataTime = dr.Item("VisitDataTime")
                patVisit.compalinedComplaints = dr.Item("CompalinedDiseases")
                patVisit.consultingDoc = dr.Item("ConsultingDoc")
                patVisit.visitNote = DataCommon.DBNullCheck(dr.Item("VisitNote"))
            End If
            dr.Close()
            SQLQuery = "Proc_GetPatientVisitProblems"
            dr = DataCommon.db.ExecuteReader(SQLQuery, objPrm)
            While dr.Read
                Dim pro As New PatientProblem
                pro.problemName = dr.Item("Problem")
                pro.reportedDateTime = dr.Item("ReportedDateTime")
                pro.period = CInt(DataCommon.DBNullCheck(dr.Item("Period")))
                pro.severityName = DataCommon.DBNullCheck(dr.Item("Severity"))
                pro.problemPeriodName = DataCommon.DBNullCheck(dr.Item("ProblemPeriod"))
                pro.problemTimingName = DataCommon.DBNullCheck(dr.Item("ProblemTiming"))
                pro.problemDurationName = DataCommon.DBNullCheck(dr.Item("ProblemDuration"))
                pro.problemLocationName = DataCommon.DBNullCheck(dr.Item("ProblemLocation"))
                patVisit.ProblemList.Add(pro)
            End While
            dr.Close()
            SQLQuery = "Proc_GetPatientVisitPrescription"
            dr = DataCommon.db.ExecuteReader(SQLQuery, objPrm)
            While dr.Read
                Dim pro As New PatientPrescription
                pro.medicineItem = dr.Item("Name")
                pro.frequencyName = DataCommon.DBNullCheck(dr.Item("Frequency"))
                pro.dosage = DataCommon.DBNullCheck(dr.Item("Dosage"))
                pro.duaration = DataCommon.DBNullCheck(dr.Item("Duaration"))
                pro.periods = DataCommon.DBNullCheck(dr.Item("Periods"))
                patVisit.TreatmentList.Add(pro)
            End While
            dr.Close()
            SQLQuery = "Proc_GetPatientVisitExamFinding"
            dr = DataCommon.db.ExecuteReader(SQLQuery, objPrm)
            While dr.Read
                Dim pro As New PatientExamFinding
                pro.findCategoryName = dr.Item("FindCategory")
                pro.findingsName = dr.Item("Findings")
                patVisit.findingList.Add(pro)
            End While
            dr.Close()
            SQLQuery = "Proc_GetPatientVisitDiagnosis"
            dr = DataCommon.db.ExecuteReader(SQLQuery, objPrm)
            While dr.Read
                Dim pro As New PatientDiagnosis
                pro.Name = dr.Item("Diagnosis")
                pro.diagnosisDateTime = DataCommon.DBNullCheck(dr.Item("DiagnosisDate"))
                pro.status = DataCommon.DBNullCheck(dr.Item("Status"))
                patVisit.DiagnosisList.Add(pro)
            End While
            dr.Close()
        Catch ex As Exception

        End Try
        Return patVisit
    End Function

    Public Overrides Function GetIPDPatientByID(ID As Integer) As HMSLibrary.PatientAddmissionInfo
        Dim patientObject As PatientAddmissionInfo = Nothing
        Try
            Dim dr As IDataReader
            SQLQuery = "EXEC Proc_GetIPDPatientByID " & ID
            dr = DataCommon.db.ExecuteReader(CommandType.Text, SQLQuery)
            If dr.Read = True Then
                patientObject = New PatientAddmissionInfo
                patientObject.AdminssionID = dr.Item("PatientAdmissionID")
                patientObject.AdminssionDate = dr.Item("AdminssionDate")
                patientObject.WardID = DataCommon.DBNullCheck(dr.Item("WardID"))
                patientObject.DepartmentID = DataCommon.DBNullCheck(dr.Item("DeptID"))
                patientObject.RoomID = DataCommon.DBNullCheck(dr.Item("RoomNo"))
                patientObject.Complaints = DataCommon.DBNullCheck(dr.Item("Diseases"))
                patientObject.Remarks = DataCommon.DBNullCheck(dr.Item("Remarks"))
                patientObject.IsDischarged = DataCommon.DBNullCheck(dr.Item("IsDischarged"))
                patientObject.DischargeDate = DataCommon.DBNullCheck(dr.Item("DischargeDate"))
                patientObject.DischargeBill = DataCommon.DBNullCheck(dr.Item("DischargeBill"))
                patientObject.PatientId = dr.Item("PatientID")
            End If
            If dr.IsClosed = False Then dr.Close()
            SQLQuery = "Exec Proc_GetPatienVisitInfo " & ID
            dr = DataCommon.db.ExecuteReader(CommandType.Text, SQLQuery)
            While dr.Read
                Dim paydtl As New BillPayDetails
                paydtl.BillID = DataCommon.DBNullCheck(dr.Item("BillPayID"))
                paydtl.Amount = DataCommon.DBNullCheck(dr.Item("Amount"))
                paydtl.BankName = DataCommon.DBNullCheck(dr.Item("BankName"))
                paydtl.Cheque_CC_No = DataCommon.DBNullCheck(dr.Item("Cheque_CC_No"))
                paydtl.ChequeDate = DataCommon.DBNullCheck(dr.Item("ChequeDate"))
                paydtl.PayModeName = DataCommon.DBNullCheck(dr.Item("Paymode"))
                patientObject.PayHistory.Add(paydtl)
            End While
            If dr.IsClosed = False Then dr.Close()
        Catch ex As Exception
            Throw ex
        End Try
        Return patientObject
    End Function

    Public Overrides Function SavePatientExam(sender As HMSLibrary.PatientGeneralExmination, Mode As HMSLibrary.FormAction) As Integer
        Try
            Dim objPRM(13) As Object
            objPRM(0) = sender.patientId
            objPRM(1) = sender.examDate
            objPRM(2) = sender.examByDr
            objPRM(3) = sender.pulse
            objPRM(4) = sender.temperature
            objPRM(5) = sender.respiration
            objPRM(6) = sender.bpup
            objPRM(7) = sender.bpdown
            objPRM(8) = sender.heartRate
            objPRM(9) = sender.height
            objPRM(10) = sender.weight
            objPRM(11) = sender.healthStatus
            objPRM(12) = sender.notes
            objPRM(13) = sender.headcircumference
            If Mode = FormAction.ADD Then
                DataCommon.db.ExecuteNonQuery("Proc_InsertPatientGeneralExminations", objPRM)
            ElseIf Mode = FormAction.EDIT Then
                ReDim Preserve objPRM(15)
                'objPRM(15) = ClientObject.ID
                'If DataCommon.db.ExecuteNonQuery( "update_tbl_ClientMaster", objPRM) = False Then Exit Function
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Overrides Function GetIPDPatientNameIDList() As System.Collections.Generic.List(Of HMSLibrary.Lookups)
        Try
            Dim dr As IDataReader = Nothing
            SQLQuery = "Exec Proc_GetIPDPatientList"
            dr = DataCommon.db.ExecuteReader(CommandType.Text, SQLQuery)
            Dim PatientList As New List(Of Lookups)
            Dim PatientObject As Lookups
            While dr.Read
                PatientObject = New Lookups
                Dim patientName As String
                patientName = dr.Item("FirstName")
                If IsDBNull(dr.Item("LastName")) = False Then
                    patientName = patientName & " " & dr.Item("LastName")
                End If
                If IsDBNull(dr.Item("SurName")) = False Then
                    patientName = patientName & " " & dr.Item("SurName")
                End If
                PatientObject.Name = patientName
                PatientObject.ID = dr.Item("PatientId")
                PatientList.Add(PatientObject)
            End While
            If dr.IsClosed = False Then dr.Close()
            Return PatientList
        Catch ex As Exception
            Throw ex
        End Try
    End Function
End Class
